package com.cheng.controller;

import com.cheng.pojo.AppCategory;
import com.cheng.pojo.BackendUser;
import com.cheng.pojo.DataDictionary;
import com.cheng.service.appcategory.AppCategoryService;
import com.cheng.service.backenduser.BackendUserService;
import com.cheng.service.datadictionary.DataDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;

@Controller
@SuppressWarnings("all")
@RequestMapping(value = "/manage")
public class BackendUserController {
    @Autowired
    private BackendUserService backendUserService;

    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String login() {
        return "backendlogin";
    }

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public String login(BackendUser backendUser, HttpServletRequest request) {
        BackendUser user = backendUserService.login(backendUser);
        if (user != null) {
            request.getSession().setAttribute("userSession", user);
            return "backend/main";
        } else {
            request.setAttribute("msg", "用户名或密码错误");
            return "backendlogin";
        }
    }
}
